#include <iostream>
#include <memory>
#include "MessageBus.h"

 MessageBus msgBus;


 class Subject: public std::enable_shared_from_this<Subject>
 {
public:
     Subject(int seq): seq_(seq){
        
     }

    ~Subject(){std::cout << "Subject desctruct: " << seq_ << std::endl;};

    void attach(){
         auto self = shared_from_this();
         msgBus.attach("drive", [&, self](std::string msg){
             std::cout << "seq: " << seq_ << " recv message: " << std::endl;
         });
    }
private:
    int seq_{0};
 };

class Car: public std::enable_shared_from_this<Subject>
 {
public:
     Car() {
         std::string msg = "car ok";
         msgBus.sendMsg("drive", msg);
     }

    ~Car(){std::cout << "Car desctruct " << std::endl;};
 };
 


int main(int argc, char* argv[]){
    {
        auto subject = std::make_shared<Subject>(1);
        subject->attach();
    }   

    std::cout << "sub 2 " << std::endl;

    // auto subject2 = std::make_shared<Subject>(2);
    // subject2->attach();

    Car car;

    return 0 ;
}